package com.example.study.controller;

import com.example.study.common.api.ResultUtil;
import com.example.study.model.TeacherVO;
import com.example.study.model.group.Insert;
import com.example.study.model.group.Update;
import com.example.study.service.TeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Api(tags = "老师管理")
@Controller
@RequestMapping("/teacher")
public class TeacherController {

    @Resource
    private TeacherService teacherService;

    /**
     * 创建老师
     * */
    @ApiOperation("创建老师")
    @RequestMapping(value = "/create_teacher", method = RequestMethod.POST)
    @ResponseBody
    public ResultUtil createTeacher(@RequestBody @Validated(Insert.class) TeacherVO teacherVO){
        return teacherService.saveTeacher(teacherVO);
    }

    /**
     * 分页查询老师
     * */
    @ApiOperation("分页查询老师")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageIndex", value = "页码(默认第一页)", dataType = "string", paramType = "query", example = "1"),
            @ApiImplicitParam(name = "pageSize", value = "每页数量(默认十条数据)", dataType = "string", paramType = "query", example = "10")})
    @RequestMapping(value = "/page_teacher", method = RequestMethod.GET)
    @ResponseBody
    public ResultUtil getTeacherPage(@RequestParam(value = "pageIndex", defaultValue = "1") int pageIndex,
                                     @RequestParam(value = "pageSize", defaultValue = "10") int pageSize,
                                     @RequestBody TeacherVO teacherVO){
        return teacherService.getTeacherPage(pageIndex, pageSize, teacherVO);
    }

    /**
     * 修改老师信息
     * */
    @ApiOperation("修改老师信息")
    @RequestMapping(value = "/update_teacher", method = RequestMethod.PUT)
    @ResponseBody
    public ResultUtil updateTeacher(@RequestBody @Validated(Update.class) TeacherVO teacherVO){
        return teacherService.updateTeacher(teacherVO);
    }

    /**
     * 删除老师信息
     * */
    @ApiOperation("删除老师信息")
    @RequestMapping(value = "/delete_teacher/{id}", method = RequestMethod.DELETE)
    @ResponseBody
    public ResultUtil deleteTeacher(@PathVariable(value = "id") Long id){
        return teacherService.deleteTeacher(id);
    }

    /**
     * 分页查询老师信息与所在班级与所带课程信息
     * */
    @ApiOperation("分页查询老师信息与所在班级与所带课程信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageIndex", value = "页码(默认第一页)", dataType = "string", paramType = "query", example = "1"),
            @ApiImplicitParam(name = "pageSize", value = "每页数量(默认十条数据)", dataType = "string", paramType = "query", example = "10")})
    @RequestMapping(value = "/page_teacher_all", method = RequestMethod.GET)
    @ResponseBody
    public ResultUtil getTeacherAllPage(@RequestParam(value = "pageIndex", defaultValue = "1") int pageIndex,
                                     @RequestParam(value = "pageSize", defaultValue = "10") int pageSize,
                                     @RequestBody TeacherVO teacherVO){
        return teacherService.getTeacherPage(pageIndex, pageSize, teacherVO);
    }

}
